<template>
  <u-tabs :list="list" :scrollable="false" v-model:current="data.current" lineWidth="82" lineHeight="4"
    lineColor="#F87610" @change="handleChange"></u-tabs>
  <block v-if="data.current == 0">
    <view v-for="(item,index) in houseList" :key="item.id" class="u-p-l-20 u-p-r-20">
      <house-item :item="item" customStyle="background:#fff" :imageWidth="234" imageHeight="192">
        <template #imgLeft>
          <image src="@/static/images/01_efr.png" v-if="item.hb_status == 2 && item.hb_residue" class="house-img"
            mode=""></image>
        </template>
        <template #right>
          <view class="u-flex-between u-flex-column u-flex-fill">
            <view class="house-name ">
              {{item.title}}
            </view>
            <view class="house-desc">“{{item.description}}”</view>
            <view class="house-info">“{{item.space}}㎡ | {{item.house_type_text}} ”</view>
            <view class="house-price u-flex-y-center u-flex-between">
              <text>市场价：{{item.market_price}}万</text>
              <text>优惠价：{{item.price}}万</text>
            </view>
          </view>
        </template>
      </house-item>
    </view>
  </block>
  <block v-else>
    <view v-for="(item,index) in articleList" :key="item.id" class="u-p-l-20 u-p-r-20">
      <house-item :item="item" customStyle="background:#fff;" :imageWidth="234" imageHeight="192" :page="`/pages/index/houseHot/articleDetail?id=${item.id}`">
        <template #imgLeft>
          <image src="@/static/images/01_efr.png" v-if="item.hb_status == 2 && item.hb_residue" class="house-img"
            mode=""></image>
        </template>
        <template #right>
          <view class="u-flex-between u-flex-column u-flex-fill">
            <view class="house-name ">
              {{item.title}}
            </view>
            <view class="house-user u-flex-between u-flex-y-center ">
              <view class="u-flex-y-center">
                <image :src="prefixURL(item.user.avatar)" class="house-avatar" mode=""></image>
                <text>{{item.user.nickname}}</text>
              </view>
              <view class="u-flex-y-center">
                <image src="@/static/images/01_32hk.png" class="house-icon" mode=""></image>
                <text>{{item.likes}}</text>
              </view>
            </view>
          </view>
        </template>
      </house-item>
    </view>
  </block>
</template>

<script setup>
  import { articleHb, houseHb } from '../../../config/api';
  import { prefixURL } from '../../../util/util';
  import houseItem from '@/components/house-item/house-item.vue'
  import { onReachBottom } from '@dcloudio/uni-app'
  import {
    onMounted,
    ref
  } from 'vue'
  const list = ref([{
    name: '每日红包'
  }, {
    name: '每日文章'
  }, ])
  const houseList = ref([])
  const articleList = ref([])
  const params = ref({
    page: 1,
    limit: 15
  })
  const data = ref({
    current: 0
  })
  onReachBottom(() => {
    params.value.page++
    if (data.value.current == 0) _houseHb()
    else _articleHb()
  })
  onMounted(() => {
    if (data.value.current == 0) _houseHb()
    else _articleHb()
  })
  // 
  const handleChange = () => {
    params.value.page = 1
    if (data.value.current == 0) _houseHb()
    else _articleHb()
  }
  // 文章
  const _articleHb = () => {
    articleHb(params.value).then(res => {
      if (params.value.page == 1) articleList.value = res.data.data
      else articleList.value = articleList.value.concat(res.data.data)
    })
  }
  // 房源
  const _houseHb = () => {
    houseHb(params.value).then(res => {
      if (params.value.page == 1) houseList.value = res.data.data
      else houseList.value = houseList.value.concat(res.data.data)
    })
  }
</script>

<style lang="scss" scoped>
  .house-img {
    position: absolute;
    top: -10rpx;
    left: 0;
    width: 108rpx;
    height: 54rpx;
  }

  .house-name {
    font-size: 26rpx;
    color: #333;
    font-weight: 800;
  }

  .house-info {
    font-size: 24rpx;
    font-weight: 500;
    color: #666;
  }

  .house-desc {
    font-size: 22rpx;
    color: #E47117;
  }

  .house-price {
    color: #DF0F0F;
    font-weight: 800;
    font-size: 24rpx;
  }

  .house-user {
    font-size: 26rpx;
    color: #333;
    font-weight: 500;

    .house-avatar {
      width: 54rpx;
      height: 54rpx;
      border-radius: 50%;
      margin-right: 10rpx;
    }

    .house-icon {
      width: 24rpx;
      margin-right: 10rpx;
      height: 34rpx;
    }
  }
</style>